<!-- 推荐职位 -->
<template>
  <div class="view-home">
    <div class="sec">
      <div class="head"></div>
      <div class="sideImg">
        <img src="../../assets/images/sideImg.png" alt="" />
      </div>
      <!-- 内容 -->
      <div class="main" id="homeMain">
        <layout-col>
          <!-- 左侧 -->
          <template #left>
            <!-- 搜索框 -->
            <div class="item searchContent">
              <span class="searchText">search >>> </span>
              <el-input
                v-model="titleSearch"
                class="search"
                size="mini"
                width="400px"
                @change="searchArtical()"
                @keyup.enter.native="searchArtical()"
              >
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
              </el-input>
            </div>
            <!-- 推荐职位列表 -->
            <JobList ref="jobListRef" />
          </template>
          <!-- 右侧 -->
          <template #right>
            <div class="right-col">
              <img
                src="../../assets/images/banner2.png"
                alt=""
                style="width: 100%; border-radius: 10px; margin-bottom: 10px"
              />
              <!-- 天气 -->
              <div class="item weather">
                <div id="he-plugin-standard"></div>
                <!-- <span class="mask"></span> -->
              </div>
              <!-- 热门公司 -->
              <div class="item hot-editor">
                <div>
                  <p class="hot-title">热门公司</p>

                  <div
                    class="ligth-text"
                    v-for="item in hotEditorList"
                    :key="item.id"
                  >
                    <a href="javascript:;" @click="clickArticalByUserId(item)">
                      <img
                        :src="item.imgSrc"
                        class="editor-img"
                        :key="item.imgSrc"
                      />
                      {{ item.name }}
                      <span class="introduce">{{ item.introduce }}</span>
                    </a>
                  </div>
                </div>
              </div>

              <!-- 推荐职位 -->
              <div class="item recommend">
                <p class="hot-title">向你推荐</p>
                <div
                  v-for="item in recommendList"
                  :key="item.id"
                  style="margin: 30px; align-items: center; cursor: pointer"
                  @click="getArticlesByCategory(item)"
                >
                  <img
                    :src="item.imgSrc"
                    alt=""
                    style="width: 30px; vertical-align: middle"
                  />
                  <span style="margin-left: 25px">{{ item.text }}</span>
                  <img
                    src="@/assets/icon/right.png"
                    alt=""
                    style="width: 20px; vertical-align: middle; float: right"
                  />
                </div>
              </div>
            </div>
          </template>
        </layout-col>
      </div>
    </div>
  </div>
</template>

<script>
let header = document.getElementById("header");
import indexImg from "@/components/indexImg.vue";
import LayoutCol from "@/components/LayoutCol.vue";
import hotEditor from "@/components/hotEditor.vue";
import JobList from "@/components/recommendList.vue";
export default {
  name: "HomeViewHome",
  components: { LayoutCol, indexImg, hotEditor, JobList },

  data() {
    return {
      userInfo: {},
      admin: "",
      hotEditorList: [
        {
          id: 0,
          name: "抖音",
          imgSrc: require("../../assets/icon/company (1).png"),
          introduce: "北京抖音信息服务有限公司",
        },
        {
          id: 1,
          name: "快手",
          imgSrc: require("../../assets/icon/company (2).png"),
          introduce: "北京快手科技有限公司",
        },
        {
          id: 2,
          name: "网易云",
          imgSrc: require("../../assets/icon/company (3).png"),
          introduce: "中国领先的互联网技术公司",
        },
        {
          id: 3,
          name: "微信",
          imgSrc: require("../../assets/icon/company (4).png"),
          introduce: "深圳市腾讯计算机系统有限公司",
        },
      ],
      recommendList: [
        {
          id: 1,
          text: "互联网",
          imgSrc: require("@/assets/icon/qianduan.png"),
        },
        {
          id: 2,
          text: "客服",
          imgSrc: require("@/assets/icon/houduan.png"),
        },
        {
          id: 3,
          text: "行政",
          imgSrc: require("@/assets/icon/Vue.png"),
        },
        {
          id: 5,
          text: "销售",
          imgSrc: require("@/assets/icon/windows.png"),
        },
        {
          id: 14,
          text: "司机",
          imgSrc: require("@/assets/icon/java.png"),
        },
      ],
      // 全屏loading
      fullscreenLoading: false,
      // 模糊搜索字段
      titleSearch: "",
      searchTitle: "",
    };
  },
  created() {
    //和风天气插件调用
    window.WIDGET = {
      CONFIG: {
        layout: "2",
        width: "250",
        height: 270,
        background: "5",
        dataColor: "000000",
        backgroundColor: "FFFFFF",
        key: "4a0c35464248447992d572a4bff4c59c",
      },
    };
    this.getWeather(document);
  },

  methods: {
    // 获取天气信息
    getWeather(d) {
      var c = document.createElement("link");
      c.rel = "stylesheet";
      c.href =
        "https://widget.qweather.net/standard/static/css/he-standard.css?v=1.4.0";
      var s = document.createElement("script");
      s.src =
        "https://widget.qweather.net/standard/static/js/he-standard.js?v=1.4.0";
      var sn = d.getElementsByTagName("script")[0];
      sn.parentNode.insertBefore(c, sn);
      sn.parentNode.insertBefore(s, sn);
    },

    // 根据热门公司id 获取对应的职位列表
    getArticlesByUserid() {
      this.$http.get(`/articles?user_id=${this.userInfo.id}`).then((res) => {
        const { code, msg, result } = res;
        if (code == 0) {
          this.searchTitle = `
           ${this.userInfo.name} 公司的所有职位`;
          this.articles = res.result;
        }
      });
    },
    clickArticalByUserId(userInfo) {
      this.reset();
      this.userInfo = userInfo;
      this.getArticlesByUserid();
    },

    // 搜索框
    searchArtical() {
      if (this.titleSearch != "") {
        this.searchTitle = `有关
           ${this.titleSearch} 的所有职位`;
        this.$http.get(`/articles?title=${this.titleSearch}`).then((res) => {
          const { code, msg, result } = res;
          if (code == 0) {
            this.$refs.jobListRef.articles = res.result;
            // this.articles = res.result;
            let doms = document.getElementsByClassName("el-message")[0];

            if (doms == undefined) {
              if (!res.result[0]) {
                this.$message({
                  showClose: true,
                  message: "没有搜索到相关职位",
                });
              }
            }
          }
        });
      } else {
        this.$message.warning({
          showClose: true,
          message: "请输入搜索内容",
        });
      }
    },
    // 根据分类获取职位列表
    getArticlesByCategory(categoryInfo) {
      this.reset();
      this.$http.get(`/articles?category_id=${categoryInfo.id}`).then((res) => {
        const { code, msg, result } = res;
        if (code == 0) {
          this.searchTitle = `有关
           ${categoryInfo.text} 的所有职位`;
          this.articles = res.result;
        }
      });
    },
    reset() {
      this.userInfo = {};
      this.searchTitle = "";
    },
  },
};
</script>
<style lang="less" scoped>
a {
  text-decoration: none;
}
.el-icon-loading {
  font-size: 20px !important;
}
.hot-title {
  text-align: left;
  margin-left: 15px;

  font-size: 20px;
}
.ligth-text {
  font-size: 20px;

  height: 30px;
  margin: 30px;

  a {
    display: flex;
    align-items: center;
    vertical-align: middle;
  }
}
.editor-img {
  width: 40px;
  margin-right: 15px;
}
.introduce {
  font-size: 15px;
  margin-left: 10px;
  letter-spacing: 1px;
}

@keyframes neon2 {
  from {
    text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff, 0 0 40px #228dff,
      0 0 70px #228dff, 0 0 80px #228dff, 0 0 100px #228dff, 0 0 150px #228dff;
  }
  to {
    text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff, 0 0 20px #228dff,
      0 0 35px #228dff, 0 0 40px #228dff, 0 0 50px #228dff, 0 0 75px #228dff;
  }
}

/*Make stuff responsive*/

@media (max-width: 650px) {
  p {
    font-size: 3.5em;
  }
}
</style>
<style lang="less" scoped>
@import "~styles/theme.styl";

.view-home {
  transition: all 0.5s;
  background-color: #f5f7fa;
  font-family: "Ubuntu", sans-serif;

  // 巨幕
  .head {
    margin-top: 100px;

    // 定位到内容
    .down {
      position: absolute;
      bottom: 50px;
      left: calc(50% - 20px);
      cursor: pointer;
      z-index: 5;

      i {
        color: var(--color);
        font-size: 40px;
        font-weight: 700;
        animation: float 2s linear infinite;
      }
    }
  }

  // 遮罩
  .mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    transition: all 0.6s;
  }

  .main {
    .left {
      .item {
        padding: 0;
      }
    }

    // 左区
    .left-col {
      ul {
        li {
        }
      }

      .el-button {
        width: 100%;
        border-radius: 10px;
        color: white;
        letter-spacing: 3px;
        margin: 20px auto;
        background-color: rgba(255, 255, 255, 0.3);
        border: none;
      }
    }

    // 右区
    .right-col {
      ul {
        li {
          cursor: pointer;
        }
      }

      .weather {
        position: relative;
        display: flex;
        justify-content: center;
        height: 300px;
        background-color: rgba(255, 255, 255, 0.3);

        .mask {
          border-radius: 10px;
        }
      }

      .hot-editor {
        height: 300px;
      }

      .recommend {
        padding-right: 15px;
        background-color: rgba(255, 255, 255, 0.3);

        h2 {
          padding-left: 5px;
          font-size: 16px;
          font-weight: bold;
          font-family: "阿里妈妈数黑体 Bold";
        }

        .recommend-article {
          display: flex;
          margin: 12px 5px 3px 5px;

          .article-cover {
            position: relative;
            width: 96px;
            height: 60px;
            border-radius: 10px;
            overflow: hidden;

            img {
              width: 100%;
              height: 100%;
              transition: all 0.6s;
            }
          }

          .article-brief {
            flex: 1;
            padding-left: 10px;
            color: rgba(255, 255, 255, 0.8);

            h3 {
              transition: all 0.3s ease-out 0s;
              font-size: 14px;
              font-weight: bold;
              word-break: break-all;
              transition: color 0.2s ease-out;
              color: rgba(255, 255, 255, 0.8);

              &:hover {
                color: #00ffff;
              }
            }

            p {
              display: flex;
              font-size: 12px;
              justify-content: space-between;
              margin-top: 10px;
              white-space: nowrap;
              color: rgba(255, 255, 255, 0.8);

              .category {
                font-size: 14px;
                color: rgba(255, 255, 255, 0.8);
              }
            }
          }
        }
      }
    }
  }
}

.searchContent {
  height: 40px !important;
  margin: 10px 0;
}

@keyframes masked-animation {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: -100%, 0;
  }
}

@keyframes float {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }

  100% {
    transform: translateY(0);
  }
}

/deep/.el-input__inner {
  width: 600px;
  background-color: #f5f7fa;
  border: none;
  color: black;
}

.searchText {
  font-family: Iceland !important;
  color: #555455;
  margin-right: 10px;
  margin-left: 20px;
  font-size: 30px;
}

.search {
  width: 60%;
}

.searchTitle {
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
  font-family: "阿里妈妈数黑体 Bold";
}

.item-bottom {
  height: 30px;
  width: 100%;
  background-color: red;
}

.sideImg {
  position: fixed;
  top: 30%;
  left: 0;
  img {
    width: 40%;
  }
}
</style>
